#include <iostream>
#include <cmath>
#include <cblas.h>
#include <vector>

// 计算两个向量的 L2 距离
double l2_distance(const std::vector<double>& x, const std::vector<double>& y) {
    int n = x.size();
    if (n != y.size()) {
        std::cerr << "Vectors must have the same length." << std::endl;
        return -1;
    }

    std::vector<double> diff(n);
    // 计算差值向量
    for (int i = 0; i < n; ++i) {
        diff[i] = x[i] - y[i];
    }

    // 计算差值向量的平方和
    double dot_product = cblas_ddot(n, diff.data(), 1, diff.data(), 1);

    // 计算平方根得到 L2 距离
    return std::sqrt(dot_product);
}

int main() {
    // 示例向量
    std::vector<double> x = {1.0, 2.0, 3.0};
    std::vector<double> y = {4.0, 5.0, 6.0};

    // 计算 L2 距离
    double distance = l2_distance(x, y);

    // 输出结果
    if (distance >= 0) {
        std::cout << "The L2 distance between the two vectors is: " << distance << std::endl;
    }

    return 0;
}